#ifndef MODBUSDEVICE_H
#define MODBUSDEVICE_H

#include "BaseDevice.h"
#include "Protocol/ModbusProtocol.h"
#include "File/Xml/ModbusListXml.h"
#include "Protocol/PointProtocol.h"
#include "Command/ModbusProtocol/ReadCoilRegisterCmd.h"
#include "Command/ModbusProtocol/ReadDiscreteCoilRegisterCmd.h"
#include "Command/ModbusProtocol/ReadHoldRegisterCmd.h"
#include "Command/ModbusProtocol/ReadInputRegisterCmd.h"

#include "Command/ModbusProtocol/WriteSignalCoilRegisterCmd.h"
#include "Command/ModbusProtocol/WriteSignalHoldRegisterCmd.h"
#include "Command/ModbusProtocol/WriteMultCoilRegisterCmd.h"
#include "Command/ModbusProtocol/WriteMultHoldRegisterCmd.h"

#include "Function/ControlPointFunc.h"
#include "Function/SendQueryDataFunc.h"

#include "PointDevice.h"
#include "LogicController/LogicController.h"
#include "Port/UART.h"
class ModbusDevice : public BaseInterface<ModbusDevice>
{
    Q_OBJECT
public:
    Q_INVOKABLE explicit ModbusDevice(QObject *parent = 0);

private:
    ModbusProtocol *modbusProtocol;
    PointProtocol *pointProtocol;
    QMap<int, QMetaObject> m_cmdMap;

    BaseModbusCmd* currentModbusCmd;
    QQueue<QSharedPointer<BaseCmd> > m_sendCmdQueue;
    bool m_isWaiting;

    void readCoilRegisterCmdHandle(PortStruct source,QSharedPointer<BaseCmd> sharedCmd);
    void readDiscreteCoilRegisterCmdHandle(PortStruct source,QSharedPointer<BaseCmd> sharedCmd);
    void readHoldRegisterCmdHandle(PortStruct source,QSharedPointer<BaseCmd> sharedCmd);
    void readInputRegisterCmdHandle(PortStruct source,QSharedPointer<BaseCmd> sharedCmd);
    void sendQueryData(QSharedPointer<BaseFunc> sharedFunc);
    void writeSignalCoilRegisterCmdHandle(PortStruct source,QSharedPointer<BaseCmd> sharedCmd);
    void writeSignalHoldRegisterCmdHandle(PortStruct source,QSharedPointer<BaseCmd> sharedCmd);
    void writeMultCoilRegisterCmdHandle(PortStruct source,QSharedPointer<BaseCmd> sharedCmd);
    void writeMultHoldRegisterCmdHandle(PortStruct source,QSharedPointer<BaseCmd> sharedCmd);
    void sendCmdQueue();
    void modbusCmdTimeoutHandle(PortStruct source,QSharedPointer<BaseCmd> sharedCmd);

    void controlPointFuncHandle(QSharedPointer<BaseFunc> sharedFunc);
};

#endif // MODBUSDEVICE_H
